import java.math.BigInteger;


public class HashRange {
	public String hashStart = "";
	public String hashEnd = "";
	public int significantBits = 0;
	
	public HashRange()
	{
		this.hashStart = "";
		this.hashEnd = "";
		this.significantBits = 0;
	}
	
	public HashRange(String hashStart, String hashEnd)
	{
		this.hashStart = hashStart;
		this.hashEnd = hashEnd;
		this.significantBits = 0;
	}
	
	public boolean hashRangeInitialized()
	{
		return !(this.hashStart.equals("") && this.hashEnd.equals(""));
	}
	
	public boolean isInRange(String hash)
	{
		BigInteger hashBI = new BigInteger(hash,16);
		BigInteger myRangeStartBI = new BigInteger(this.hashStart,16);
		BigInteger myRangeEndBI = new BigInteger(this.hashEnd,16);
		int comp1 = hashBI.compareTo(myRangeStartBI);
		int comp2 = hashBI.compareTo(myRangeEndBI);
		boolean gteStart = comp1==0 || comp1==1;
		boolean lteEnd = comp2==-1 || comp2==0;
		
		return (gteStart && lteEnd);
	}
	
	public BigInteger getHashStartBI()
	{
		return new BigInteger(this.hashStart,16);
	}
	
	public BigInteger getHashEndBI()
	{
		return new BigInteger(this.hashEnd,16);
	}
}
